package com.lepu.app.usercenter;

import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.app.utils.Setting;
import com.app.utils.UpdateManager;
import com.core.lib.application.BaseFragmentActivity;
import com.eyzhs.app.R;
import com.lepu.app.main.activity.AppBroswerActivity;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;

public class AboutMainActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.usercenter_about_main_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}

	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("关于我们");
		topbar.setonTopbarNewLeftLayoutListener(this);
		
		//update version info
		String version = "";
		try {
			version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}

		String debug = "";
		if(Setting.DEBUG)
		{
			debug = " beta ";
		}
		
		TextView versionTextView = (TextView) findViewById(R.id.versionTextView);
		String appName = getString(R.string.app_name);
		versionTextView.setText(appName + debug + version);
	}

	public void layoutClick(View view) {
		
		Intent intent = null;
		
		switch (view.getId()) {
		case R.id.versionUpdateLayout:
			UpdateManager.getInstance().checkUpdate(false,Setting.getCheckUpdate(), this,
					true,true);
			break;
		case R.id.aboutWeLayout:
			
			intent = new Intent(this,AppBroswerActivity.class);
			intent.putExtra("title", "关于我们");
			intent.putExtra("url", "file:///android_asset/about_us/about_us.html");
			startActivity(intent, true);
			
			break;
		case R.id.userProtocolLayout:

			intent = new Intent(this,AppBroswerActivity.class);
			intent.putExtra("title", "用户服务协议");
			intent.putExtra("url", Setting.getUserProtocolUrl());
			startActivity(intent, true);
			
			break;
		case R.id.secretLayout:

			intent = new Intent(this,AppBroswerActivity.class);
			intent.putExtra("title", "隐私政策");
			intent.putExtra("url", Setting.getUserSecretUrl());
			startActivity(intent, true);
			break;

		default:
			break;
		}
	}

	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}

}
